package com.example.mapper;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.suspectProductListPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface suspectProductListMapp {

    //新建并插入一条新的数据 ==> 向可疑品数据表中
    @DS("newMscLowCodeFormal")
    @Insert("insert into ddm_suspect_product_list (" +
            "id, create_time, update_time, " +
            "creator, process_status, sys_update_user, " +
            "sys_audit_user, sys_audit_time, sys_deleted, " +
            "part_name, part_supplier, model_id, occur_date, " +
            "link, position, occur_per, part_id,describe_use,part_num, " +
            "judgement, from_judgment, from_process, unqualified, rework, " +
            "solve, judged_by, confirmed_by, defective_product_list, " +
            "status1, status2, is_trace_finish, is_deal_finish) " +
            "VALUES " +
            "(#{id}, #{create_time}, #{update_time}, " +
            "#{creator}, #{process_status}, #{sys_update_user}, " +
            "#{sys_audit_user}, #{sys_audit_time}, #{sys_deleted}," +
            "#{part_name}, #{part_supplier}, #{model_id}, #{occur_date}, " +
            "#{link}, #{position}, #{occur_per}, #{part_id},#{describe_use},#{part_num}," +
            "#{judgement}, #{from_judgment}, #{from_process}, #{unqualified}, #{rework}, " +
            "#{solve}, #{judged_by}, #{confirmed_by}, #{defective_product_list}, " +
            "#{status1}, #{status2}, #{is_trace_finish}, #{is_deal_finish})")
    void insertOne( suspectProductListPojo Pojo );

    //查询所有的数据并返回查询到数据，返回的数值为list格式，根据表中的删除标记，只显示sys_deleted=0的数据 ，时间范围是10个月，时间倒序
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_suspect_product_list where sys_deleted=0 AND occur_date >= NOW() - INTERVAL 10 MONTH order by occur_date desc")
    List<suspectProductListPojo> queryAll();

    //分页查询可疑品清单
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_suspect_product_list where " +
            "sys_deleted=0 " +
            "and " +
            "link=#{link} " +
            "AND occur_date >= NOW() - INTERVAL 10 MONTH " +
            "order by occur_date DESC " +
            "limit #{startRow}, #{size}")
    List<suspectProductListPojo> queryByPage(Integer startRow, Integer size, String link);

    //查询所有可疑品清单条数
    @DS("newMscLowCodeFormal")
    @Select("SELECT COUNT(*) FROM ddm_suspect_product_list where sys_deleted=0 and link=#{link}")
    Integer queryQuantity(String link);

    //修改一条数据，更新到数据库中。
    @DS("newMscLowCodeFormal")
    @Update(value = "update ddm_suspect_product_list set " +
            "create_time=#{create_time}, " +
            "update_time=#{update_time}, " +
            "creator=#{creator}, " +
            "process_status=#{process_status}, " +
            "sys_update_user=#{sys_update_user}, " +
            "sys_audit_user=#{sys_audit_user}, " +
            "sys_audit_time=#{sys_audit_time}, " +
            "sys_deleted=#{sys_deleted}, " +
            "part_name=#{part_name}, " +
            "part_supplier=#{part_supplier}, " +
            "model_id=#{model_id}, " +
            "occur_date=#{occur_date}, " +
            "link=#{link}, " +
            "position=#{position}, " +
            "occur_per=#{occur_per}, " +
            "part_id=#{part_id}, " +
            "describe_use=#{describe_use}, " +
            "part_num=#{part_num}, " +
            "judgement=#{judgement}, " +
            "from_judgment=#{from_judgment}, " +
            "from_process=#{from_process}, " +
            "unqualified=#{unqualified}, " +
            "rework=#{rework}, " +
            "solve=#{solve}, "+
            "judged_by=#{judged_by}, "+
            "confirmed_by=#{confirmed_by}, "+
            "defective_product_list=#{defective_product_list}, " +
            "status1=#{status1}, " +
            "status2=#{status2}, " +
            "is_trace_finish=#{is_trace_finish}, " +
            "is_deal_finish=#{is_deal_finish} "+
            "where id=#{id} ")
    void editOne(suspectProductListPojo pojo);


    //查询指定条件的数据，并展示到可疑品列表中
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_suspect_product_list where sys_deleted=0 and ${fieldName}=#{fieldVal}")
    List<suspectProductListPojo> queryOneField(String fieldName, String fieldVal);

    //根据ID、指定的字段、指定的值，对数据表的一条内容进行编辑
    @DS("newMscLowCodeFormal")
    @Select("update ddm_suspect_product_list set ${fieldName}=#{fieldVal} where id=#{id}")
    void editOneFiledById(String id, String fieldName, String fieldVal);
    @DS("newMscLowCodeFormal")
    @Select("update ddm_suspect_product_list set ${fieldName1}=#{fieldVal1},${fieldName2}=#{fieldVal2} where id=#{id}")
    void editTwoFiledsById(String id, String fieldName1, String fieldVal1, String fieldName2, String fieldVal2);

    //查询指定条件的数据,根据筛选的日期值进行筛选数据并返回
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_suspect_product_list where sys_deleted=0 " +
            "and ${fieldName}>=#{minVal} and ${fieldName}<=#{maxVal} order by ${fieldName} desc " )
    List<suspectProductListPojo> queryByTimeScope(String fieldName, LocalDateTime minVal, LocalDateTime maxVal);

    //多条件筛选可疑品清单
    @DS("newMscLowCodeFormal")
    List<suspectProductListPojo> filterSuspectProduct(Integer startRow, Integer size, String link, String occurPerson, String startTime, String endTime, String status1);
    //多条件筛选可疑品清单总条数
    @DS("newMscLowCodeFormal")
    Integer filterSuspectProductQuantity(String link, String occurPerson, String startTime, String endTime, String status1);
}
